import mongoose, { Schema, Document } from 'mongoose';

export interface IUser extends Document {
    username: string;
    email: string;
    password: string;
    vip: string;
    avatar: string;
    bookshelf: Array<any>;
    study_time: Array<any>;
    token?: string;
    refreshToken?: string;  // 添加 Refresh Token
}

const UserSchema: Schema = new Schema({
    username: { type: String, required: true, unique: true },
    email: { type: String, required: true, unique: true },
    password: { type: String, required: true },
    avatar: { type: String, default: "" },
    bookshelf: { type: Array, default: [] },
    vip: { type: String, default: "common" },
    study_time: { type: Array, default: [] },
    token: { type: String, default: "" },
    refreshToken: { type: String, default: "" }, // 用于存储长期 token
}, { timestamps: true });

export default mongoose.models.User || mongoose.model<IUser>('User', UserSchema);

